#include <iostream>
#include <cstring>
using namespace std;
int N;
int pipe[15];
void solve();
int top[2]; // 两个人的顶端
bool success;
int main() {
    cin >> N;
    while (N--) {
        memset(top, 0, sizeof top);
        success = false;
        for (int i = 0; i < 10; i++)
            cin >> pipe[i];
        solve();
    }
}


void dfs(int index) {
    if (index == 10) {
        success = true;
        return;
    }
    int t0 = top[0], t1 = top[1];
    if (pipe[index] > top[0]) {
        top[0] = pipe[index];
        dfs(index + 1);
        top[0] = t0;
    }

    if (pipe[index] > top[1]) {
        top[1] = pipe[index];
        dfs(index + 1);
        top[1] = t1;
    }
    
}

void solve() {
    dfs(0);
    if (success) cout << "YES" << endl;
    else cout << "NO" << endl;
}